﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Aandelendelen.Controls
{
	public partial class BannerControl : UserControl
	{
		public string NavigateUrl = "/BannerClicked.aspx";
		public string TargetUrl;
		public string ImageUrl;
		public string Text;
		public bool isAdsense = true;
		public int adId;

		protected override void Render(HtmlTextWriter writer)
		{
			if (!this.isAdsense)
				this.RenderHyperlink(writer);
			else
				this.RenderAdsense(writer);
		}

		private void RenderHyperlink(HtmlTextWriter writer)
		{
			HyperLink hyperLink = new HyperLink();

			hyperLink.NavigateUrl = NavigateUrl + "?id=" + this.adId.ToString() + "&url=" + this.TargetUrl;
			hyperLink.Target = "_blank";
			hyperLink.ImageUrl = this.ImageUrl;
			hyperLink.Text = this.Text;
			hyperLink.ToolTip = this.Text;
			hyperLink.Attributes["rel"] = "nofollow";

			this.Controls.Add(hyperLink);

			base.Render(writer);
		}

		private void RenderAdsense(HtmlTextWriter writer)
		{
			writer.Write("<div style=\"margin-top:34px\">"); //make room for drop down menu
			writer.Write("<script type=\"text/javascript\"><!--\r\n");
			writer.Write(" google_ad_client = \"pub-6728413239268485\";\r\r");
			writer.Write(" /* 468x60Banner, created 1/13/11 */\r\n");
			writer.Write(" google_ad_slot = \"0848118656\";\r\n");
			writer.Write(" google_ad_width = 468;\r\n");
			writer.Write(" google_ad_height = 60;\r\n");
			writer.Write(" //-->\r\n");
			writer.Write(" </script>\r\n");
			writer.Write(" <script type=\"text/javascript\"\r\n");
			writer.Write(" src=\"http://pagead2.googlesyndication.com/pagead/show_ads.js\">\r\n");
			writer.Write(" </script>");
			writer.Write("</div>");
		}

	}
}